package java929_1;

//教员要求张浩使用面对对象思想编写一个计算器(Calculator)，
// 可以实现两个整数的加，减，乘，除运算。

import java.util.Scanner;

public class Calculator {
    int num1;
    int num2;
    int typeid;

    public void count() {
        if (num2 == 0 && typeid == 4) {
            System.err.println("除数不能为0！！");
        } else {
            switch (typeid) {
                case 1:
                    System.out.println("加法：" + (num1 + num2));
                    break;
                case 2:
                    System.out.println("减法:" + (num1 - num2));
                    break;
                case 3:
                    System.out.println("乘法:" + (num1 * num2));
                    break;
                case 4:
                    System.out.println("除法:" + (num1 / num2));
                    break;
                default:
                    break;

            }
        }

    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Calculator c = new Calculator();
        System.out.print("请输入第一个整数：");
        c.num1 = input.nextInt();
        System.out.print("请输入第二个整数：");
        c.num2 = input.nextInt();
        System.out.println("1.加，2.减3.乘，4.除");
        System.out.print("请选择：");
        c.typeid = input.nextInt();
        c.count();
    }
}



